Add the following to the winmain function in the project file:
Code (This code runs in bcb6.0 ):
Handle hmutex = createmutex (null, false, "process ");
If (getlasterror () = error_already_exists)
{
Closehandle (hmutex );
MessageBox (Application->
Compiler Error:Parameter 3 cannot be converted from "const char [8]" to "LPCWSTR" and changed to LPCWSTR typeChange method:Hmutex=createmutex (null,true,l "tickets")You just need to add a capital L to the third argument, which is preceded by the
Createmutex
Function
Check whether the current system has an instance of the specified process. If not, create a mutex. The createmutex () function can be used to create a famous or unknown mutex object. Its function prototype is
VC statement
Example: Hmutex = CreateMutex (NULL, FALSE, "screen");Error C2664: "CREATEMUTEXW": Cannot convert parameter 3 from "const char [7]" to "LPCWSTR"Not related to the type that is pointed to, conversion requires reinterpret_cast, C-style conversion, or
Reproduced in NetEase blog: http://jiafeng26.blog.163.com/blog/static/1754251920100140134147/
Windows is a multi-user and multi-task operating system that supports multipleProgramRun at the same time. If your program does not want users to run
Note: This article is very brief. If you feel difficult to understand, please refer to another article that is much better than mine.Let's look at an example first1#include 2#include 3 4DWORD WINAPI Reportfunc (LPVOID);//generic prototype of a
The WinMain function is a Windows application entry point that is provided to the user and is prototyped as follows:int WINAPI WinMain (hinstance hinstance, hinstance hprevinstance, LPSTR ipcmdline, int ncmdshow);The function has four
In Windows, the program prevents multiple common methods:1) Use the findwindow API function.You can query the window title (or/and Class Name) to determine whether the program is running. If it is found, it indicates that the program is running, and
Principle Analysis:A mutex is a system kernel object that can be owned by each thread and executed by anyone;After the execution is complete, use the releasemutex function to release the ownership so that other waiting threads can use it.Other
In Windows, the program prevents multiple common methods:1) Use the findwindow API function.Locate the window title (or/and class name)ProgramWhether it is running. If it is found, it indicates that the program is running, and you can exit the
This is a very simple method. By creating a mutex object, you can also verify that an instance with this program is running.
Greatemutex function prototype:
Handle createmutex (Lpsecurity_attributes lpmutexattributes,Bool
Mutex is a simple form of synchronization (called mutex )). The mutex prohibits multiple threads from entering the protected code "critical section" at the same time ). Therefore, at any time, only one thread is allowed to enter such a code
In a multi-threaded environment, each thread has its own local thread stack and register. This value may be incorrect if multiple threads can read and write the same resource. For example, when two threads read and write the same data, the data will
There are three ways to share kernel objects across process boundaries:
Inheritance of object handles
Named objects
Copy object handle
named ObjectsThe second way to share kernel objects that span process boundaries is to name
This article describes the VC + + process and multi-process management methods, share for everyone to reference. The specific methods are analyzed as follows:
absrtact : This paper mainly introduces the multi-process management technology in
Sometimes, we need to run only one instance of our program, the author of their own procedures have such a situation, so I have to explore some. After a while, finally small harvest, do not dare to enjoy, in pole published for your reference.
Since
Delphi methods for multi-thread synchronization
A thread is a relatively independent and schedulable execution unit in a process. An application can have a main thread, a main thread can have multiple sub-threads, and a sub-thread can also have
Implement applicationsProgramThere are many ways to run a single instance. If there is a window application, you can use findwindow () to find out whether a window with the same name already exists. For windowless applications, you can use the
Mutex applications for multi-thread synchronization on windows, multi-thread mutex
Mutex application for multi-thread synchronization on windows
Preface Thread Composition:
The Zookeeper operating system schedules a certain CPU time for each
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.